package com.eyolo.grpcserver.server.service;

import com.eyolo.grpcserver.server.mq.RocketMqSender;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import scwrapper.Sc;

import javax.annotation.Resource;
import java.util.UUID;

@Slf4j
@Service
public class SCWrapperService {

    @Resource
    private RocketMqSender rocketMqSender;

    /**
     * 模拟铸销币
     */
    public void applyExchange(Sc.ApplyExchangeReq request) {
        log.info("正在铸销币");
        log.info("完成铸销币");
        Sc.OrderInfo orderInfo = Sc.OrderInfo.newBuilder()
                .setOrderID(UUID.randomUUID().toString())
                .setStartTime(System.currentTimeMillis())
                .setEndTime(System.currentTimeMillis())
                .setAmount(request.getFromAmount())
                .setAmountCoinName(request.getFromCoinName())
                .setToAmount(request.getFromAmount())
                .setToCoinName(request.getToCoinName())
                .setAccountID("该订单所有人AccountID")
                .setBusAccountID("业务侧传入的accountId")
                .setBusIdentity(request.getBusIdentity())
                .setOrderStatus(Sc.OrderInfo.OrderInfoStatusEnum.OrderInfoStatusEnum_SUCC)
                .build();
        if (request.getToCoinName().equals("usdx")) {
            rocketMqSender.sentMintResultMsg(orderInfo);
        } else {
            rocketMqSender.sentBurnResultMsg(orderInfo);
        }
        log.info("铸销币成功");
    }

}
